<?php

class spTableRow extends spElement
{
	public function  __construct( $param=null )
	{
		parent::__construct( "tr", $param );
		
		if ( isset($param["headercols"]) )
			$this->addHeaderCols( $param["cols"] );
	}

	public function addCols( $ar )
	{
		if ( !is_array($ar) )
		{
			return $this->addTableData( $ar );
		}

		$list = array();
		foreach ( $ar as $a )
		{
			$list[] = $this->addTableData( $a );
		}
		return $list;
	}
	
	public function addHeaderCols( $ar )
	{
		if ( !is_array($ar) )
		{
			return $this->addTableHeaderData( $ar );
		}
		
		$list = array();
		foreach ( $ar as $a )
		{
			$list[] = $this->addTableHeaderData( $a );
		}
		return $list;
	}

	// this method is deprecated (use addTableData)
	public function addCell( $c=null )
	{
		$cell = new spTableData;
		parent::addChild( $cell );
		
		if ( $c )
			$cell->addChild( $c );
		
		return $cell;
	}
	
	public function addTableData( $data="" )
	{
		if ( $data instanceof spTableData )
		{
			parent::addChild( $data );
			return $data;
		}
		
		if ( $data instanceof spElement )
		{
			$cell = new spTableData(array(
				"child" => $data
			));
			parent::addChild( $cell );
			return $cell;
		}
		
		$cell = new spTableData(array(
			"content" => $data
		));
		parent::addChild( $cell );
		
		return $cell;
	}

	public function addTableHeaderData( $data )
	{
		if ( $data instanceof spTableHeaderData )
		{
			parent::addChild( $data );
			return $data;
		}
	
		if ( $data instanceof spElement )
		{
			$cell = new spTableHeaderData(array(
				"child" => $data
			));
			parent::addChild( $cell );
			return $cell;
		}
		
		$cell = new spTableHeaderData(array(
			"content" => $data
		));
		parent::addChild( $cell );
		
		return $cell;
	}
}

?>